package com.ruoyi.core.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.core.service.VersionService;
import com.ruoyi.core.vo.VersionVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author xiaom
 * @Date 2020/12/19 15:16
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@Validated
@Api(tags = "版本管理")
@RequestMapping("/client-version")
public class VersionController extends BaseController {

    @Autowired
    private VersionService versionService;

    @GetMapping(value = "/getVersion")
    @ApiOperation("获取最新版本")
    public AjaxResult getVersion(){
        return AjaxResult.success(versionService.getLastVersion());
    }

    @PostMapping(value = "/addVersion")
    @ApiOperation("添加新版本")
    public AjaxResult addVersion(@RequestBody @Valid VersionVo versionVo){
        return AjaxResult.success(versionService.addVersion(versionVo));
    }

    @GetMapping(value = "/getListData")
    @ApiOperation("获取版本列表")
    public TableDataInfo getLisData(){
        startPage();
        return getDataTable(versionService.getList());
    }

    @GetMapping(value = "/deleteVersion")
    @ApiOperation("删除版本")
    public AjaxResult deleteVersion(@RequestParam Long id){
        return AjaxResult.success(versionService.deleteVersion(id));
    }
}
